package com.mszlu.news.controller;

import com.mszlu.news.service.CategoryService;
import com.mszlu.news.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "类型接口")
@RestController
@RequestMapping("categorys")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    // /categorys
    @ApiOperation(value = "查找所有类型")
    @GetMapping
    public Result categories() {
        return categoryService.findAll();
    }

    @ApiOperation(value = "查找所有类型及详情")
    @GetMapping("detail")
    public Result categoriesDetail() {
        return categoryService.findAllDetail();
    }

    ///category/detail/{id}
    @ApiOperation(value = "通过文章id查找其类型")
    @GetMapping("detail/{id}")
    public Result categoryDetailById(@PathVariable("id") Long id) {
        return categoryService.categoryDetailById(id);
    }

    @ApiOperation(value = "统计其类型文章观看数")
    @PostMapping("categoryCounts/{id}")
    public Result categoryCountsById(@PathVariable("id") Long id) {
        return categoryService.categoryCountsById(id);
    }
}
